const gulp = require('gulp');
const kitty = require('vkitty');
const serve = require('kitty-serve');
const less= require('less');
var loaders = kitty.loaders;

var type = 'dev';
var envConfig = {
    dev:{
        host:"127.0.0.1:7001"
    },
    devDaily:{
        host:"crmdev.adbaitai.com"
    },
    daily:{
        host:"crmdev.adbaitai.com"
    },
    pre:{
        host:"crmpre.adbaitai.com"
    },
    prod:{
        host:"crm.adbaitai.com"
    }
};


loaders.beforeCompile =  function(content){
    content = content.replace('127.0.0.1:7001',envConfig[type].host);
    return content;
};

gulp.task('dev',function(){
    type= 'dev';
    kitty.watch('./src/pages/*/index.html')
        .pipe(serve.src({
            port:8084,
            prePath:"/maliang"
        }))
        .pipe(serve.cdn({
            port:8085
        }))
});

gulp.task('devDaily',function(){
    type= 'devDaily';
    kitty.watch('./src/pages/*/index.html')
        .pipe(serve.src({
            port:8084,
            prePath:"/maliang"
        }))
        .pipe(serve.cdn({
            port:8085
        }))
});


gulp.task('pre',function(){
    type= 'pre';
    kitty.src('./src/pages/*/index.html')
        .pipe(kitty.dest('./build'))
});

gulp.task('prod',function(){
    type= 'prod';
    kitty.src('./src/pages/*/index.html')
        .pipe(kitty.dest('./build'))
});


gulp.task('mock', function () {
    kitty.watch(['./mock/**/*action','./mock/**/*et','./mock/*/getLottery'])
        .pipe(serve.src(
            {
                port: 7001,
                prePath:"/api",
                headers: {
                    "Content-Type":"application/json;charset=UTF-8",
                    "Access-Control-Allow-Origin": "http://static.dev.adbaitai.com",
                    "Access-Control-Allow-Credentials": "true"
                }
            }
        ))
});
